home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 5.6 KB | 228 lines | [TEXT/KAHL] |
- /****
- * CAppPiPane.c
- *
- * Pane methods for a typical application.
- *
- * Copyright © 1990 Symantec Corporation. All rights reserved.
- *
- ****/
-
- /**
- *
- * Most applications will want a scrollable window, so this
- * class is based on the class CPanorama. All the methods here
- * would still apply to classes based directly on CPane.
- *
- **/
-
- #include "CAppPiPane.h"
- #include <stdio.h>
-
- #define Margin 5
-
- void DrawWrapText (char *text, long count, short leftMargin, short rightMargin, short lineMargin, Boolean forceMargin);
-
-
- void CAppPiPane::IAppPiPane(CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight,
- short aHEncl, short aVEncl,
- SizingOption aHSizing, SizingOption aVSizing)
- {
- CPanorama::IPanorama(anEnclosure, aSupervisor, aWidth, aHeight,
- aHEncl, aVEncl, aHSizing, aVSizing);
-
- pi = nil;
- time = 0;
- }
-
-
- char *CAppPiPane::GetContent (void)
- {
- return (this->pi);
- }
-
-
- void CAppPiPane::SetContent (char *result, long ticks, long digits)
- {
- char *s;
-
- if (this->pi != nil) // Dispose existing ptr.
- DisposPtr (this->pi);
-
- this->pi = result; // Save passed in data.
- this->time = ticks;
- this->numDigits = digits;
-
- for (s = pi; s < pi + numDigits; s++)
- *s += '0'; // Convert to numbers.
- }
-
-
- /***
- * Draw
- *
- * In this method, you draw whatever you need to display in
- * your pane. The area parameter gives the portion of the
- * pane that needs to be redrawn. Area is in frame coordinates.
- *
- ***/
-
- void CAppPiPane::Draw(Rect *area)
-
- {
- short font;
- short charWidth;
- Str255 title;
- LongRect ap;
- char *s;
- long output;
- short i, numChars;
-
- if (pi == nil)
- return;
-
- GetFNum ("\pMonaco", &font);
- TextFont (font);
- TextSize (9);
-
- GetAperture (&ap);
-
- MoveTo (0, 20);
- if (time == 0)
- title[0] = sprintf ((char *) title + 1, "The value of π calculated to %ld digits:", numDigits);
- else
- title[0] = sprintf ((char *) title + 1, "The value of π calculated to %ld digits in %ld seconds:", numDigits, time / 60);
- DrawWrapText ((char *) title + 1, title[0], Margin, ap.right - Margin, 0, true);
-
- MoveTo (0, 50);
- DrawWrapText (pi, 1, Margin, ap.right - Margin, 0, true);
- DrawWrapText (".", 1, Margin, ap.right - Margin, 0, false);
- DrawWrapText (pi + 1, numDigits - 1, Margin, ap.right - Margin, 0, false);
-
- }
-
-
- /***
- * DoClick
- *
- * The mouse went down in the pane.
- * In this method you do whatever is appropriate for your
- * application. HitPt is given in frame coordinates. The other
- * parameters, modiferKeys and when, are taken from the event
- * record.
- *
- * If you want to implement mouse tracking, this is the method
- * to do it in. You need to create a subclass of CMouseTask and
- * pass it in a TrackMouse() message to the pane.
- *
- ***/
-
- void CAppPiPane::DoClick(Point hitPt, short modifierKeys, long when)
-
- {
- /* what happens when the mouse goes down */
- }
-
-
- /***
- * HitSamePart
- *
- * Test whether pointA and pointB are in the same part.
- * "The same part" means different things for different applications.
- * In the default method, "the same part" means "in the same pane."
- * If you want a different behavior, override this method. For instance,
- * two points might be in the same part if they're within n pixels
- * of each other.
- *
- * PointA and pointB are both in frame coordinates.
- *
- ***/
-
- Boolean CAppPiPane::HitSamePart(Point pointA, Point pointB)
-
- {
- return inherited::HitSamePart(pointA, pointB);
- }
-
-
- /***
- * AdjustCursor
- *
- * If you want the cursor to have a different shape in your pane,
- * do it in this method. If you want a different cursor for different
- * parts of the same pane, you'll need to change the mouseRgn like this:
- * 1. Create a region for the "special area" of your pane.
- * 2. Convert this region to global coordinates
- * 3. Set the mouseRgn to the intersection of this region
- * and the original mouseRgn: SectRgn(mouseRgn, myRgn, mouseRgn);
- *
- * The default method just sets the cursor to the arrow. If this is fine
- * for you, don't override this method.
- *
- ***/
-
- void CAppPiPane::AdjustCursor(Point where, RgnHandle mouseRgn)
-
- {
- inherited::AdjustCursor(where, mouseRgn);
- }
-
-
- /***
- * ScrollToSelection
- *
- * If your pane is based on a Panorama (as this example is), you might
- * want to define what it means to have a selection and what it means to
- * scroll to that selection.
- *
- ***/
-
- void CAppPiPane::ScrollToSelection(void)
-
- {
- /* scroll to the selection */
- }
-
-
- /* Draw text that wraps from line to line. Count characters from text. The
- leftMargin and rightMargin are the point locations in the window where the
- margins are. The lineMargin is the line spacing, if zero, it's set from
- the font. If forceMargin is true, then the routine starts from the left
- margin. */
- void DrawWrapText (char *text, long count, short leftMargin, short rightMargin, short lineMargin, Boolean forceMargin)
- {
- Point pt;
- FontInfo fInfo;
- long lineStart, lineEnd, lineSize, trySize;
-
- if (forceMargin) {
- GetPen (&pt); // Move to left margin.
- Move (leftMargin - pt.h, 0);
- }
-
- GetFontInfo (&fInfo); // Set line margin.
- if (lineMargin == 0)
- lineMargin = fInfo.ascent + fInfo.descent + fInfo.leading;
-
- // Text is short, don't need to wrap it.
- if (count < ((rightMargin - leftMargin) / fInfo.widMax)) {
- DrawText (text, 0, count);
- return;
- }
-
- // Need to wrap text.
- GetPen (&pt);
- lineSize = rightMargin - pt.h;
-
- for (lineStart = lineEnd = 0; lineEnd < count; ) {
- for (trySize = 0; trySize <= lineSize && lineEnd < count; lineEnd++) {
- trySize += CharWidth (text[lineEnd]);
- }
- DrawText (text, lineStart, lineEnd - 1 - lineStart);
- GetPen (&pt);
- Move (leftMargin - pt.h, lineMargin);
- lineSize = rightMargin - leftMargin;
- lineStart = lineEnd;
- }
- }
-